package com.ruoyi.fztz.fykmgl.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.fztz.fykmgl.domain.Fykm;
import com.ruoyi.fztz.fykmgl.service.IFykmService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import java.io.InputStream;
import org.springframework.web.multipart.MultipartFile;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 费用科目管理Controller
 *
 * @author huacai
 * @date 2024-11-19
 */
@RestController
@RequestMapping("/fztz/fykm")
public class FykmController extends BaseController
{
    @Autowired
    private IFykmService fykmService;

    /**
     * 查询费用科目管理列表
     */
    @PreAuthorize("@ss.hasPermi('fztz:fykm:list')")
    @GetMapping("/list")
    public AjaxResult list(Fykm fykm)
    {
        List<Fykm> list = fykmService.selectFykmList(fykm);
        return success(list);
    }

    /**
     * 导出费用科目管理列表
     */
    @PreAuthorize("@ss.hasPermi('fztz:fykm:export')")
    @Log(title = "费用科目管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, Fykm fykm)
    {
        List<Fykm> list = fykmService.selectFykmList(fykm);
        ExcelUtil<Fykm> util = new ExcelUtil<Fykm>(Fykm.class);
        util.exportExcel(response, list, "费用科目管理数据");
    }

    /**
     * 下载模板
     */
    @PostMapping("/importTemplate")
    public void importTemplate(HttpServletResponse response)
    {
        ExcelUtil<Fykm> util = new ExcelUtil<Fykm>(Fykm.class);
        util.importTemplateExcel(response, "费用科目管理数据");
    }

    /**
     * 导入数据
     */
    @Log(title = "费用科目管理", businessType = BusinessType.IMPORT)
    @PreAuthorize("@ss.hasPermi('fztz:fykm:import')")
    @PostMapping("/importData")
    public AjaxResult importData(MultipartFile file) throws Exception
    {
        ExcelUtil<Fykm> util = new ExcelUtil<Fykm>(Fykm.class);
        InputStream inputStream = file.getInputStream();
        List<Fykm> list = util.importExcel(inputStream );
        inputStream.close();
        int count = fykmService.batchInsertFykm(list);
        return AjaxResult.success("导入成功" + count + "条信息！");
    }

    /**
     * 获取费用科目管理详细信息
     */
    @PreAuthorize("@ss.hasPermi('fztz:fykm:query')")
    @GetMapping(value = "/{fykmId}")
    public AjaxResult getInfo(@PathVariable("fykmId") Integer fykmId)
    {
        return success(fykmService.selectFykmByFykmId(fykmId));
    }

    /**
     * 新增费用科目管理
     */
    @PreAuthorize("@ss.hasPermi('fztz:fykm:add')")
    @Log(title = "费用科目管理", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Fykm fykm)
    {
        return toAjax(fykmService.insertFykm(fykm));
    }

    /**
     * 修改费用科目管理
     */
    @PreAuthorize("@ss.hasPermi('fztz:fykm:edit')")
    @Log(title = "费用科目管理", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Fykm fykm)
    {
        return toAjax(fykmService.updateFykm(fykm));
    }

    /**
     * 删除费用科目管理
     */
    @PreAuthorize("@ss.hasPermi('fztz:fykm:remove')")
    @Log(title = "费用科目管理", businessType = BusinessType.DELETE)
	@DeleteMapping("/{fykmIds}")
    public AjaxResult remove(@PathVariable Integer[] fykmIds)
    {
        return toAjax(fykmService.deleteFykmByFykmIds(fykmIds));
    }
}
